package com.fm.demo.activity.dualScreen

import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import com.blankj.utilcode.util.LogUtils
import com.fm.common.base.BaseBActivity
import com.fm.demo.databinding.ActivityDualScreenBinding

/**
 * @CreateData:     2019/11/15 15:01
 * @E-Mail:         709674174@qq.com
 * @Author:         lyy
 * @Description:    测试模块入口
 */
class DualScreenActivity : BaseBActivity<ActivityDualScreenBinding>() {
    private var mTestDisplay: TestDisplay? = null

    override fun initView(savedInstanceState: Bundle?) {
        initDisplay()
        binding.dsBtnDualSetData.setOnClickListener {
            mTestDisplay?.setTitle("DualScreenActivity")
        }
    }

    /**
     * 初始化第二屏
     */
    private fun initDisplay() {
        val displayManager: DisplayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
        val displays = displayManager.displays
        LogUtils.e("display size : ${displays.size}")
        if (displays.size >= 2) {
            mTestDisplay = TestDisplay(mContext, displays[1])
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                mTestDisplay?.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
            }
            mTestDisplay?.show()
        }
    }


}
